export abstract class MessageType {
    abstract type: string;
    [key: string]: any

    /** 将 messageChain 也就是 MessageType类型的数组 转换成命令，也就是将收到的QQ消息转换成可执行的命令 */
    static toCommand(messageChain: MessageType[]): string {
        // 1. 过滤无关类型
        let arr = messageChain.filter(e => ["Plain", "At"].indexOf(e.type) !== -1);

        // 2. 将类型都转换成文本类型
        const textArr = arr.map(e => {
            if (e.type == "Plain") {
                return e.text
            }
            if (e.type == "At") {
                return e.target
            }
        })

        // 3. 按空格分割 方便执行
        return textArr.join(" ")
    }
    /** 将QQ转换成AT的格式 */
    static toAt(qq: string): MessageType {
        return {
            "type": "At",
            "target": qq,
            "display": "@XiaoZhi"
        }
    }
    /** 将字符串转换成普通文本消息格式 */
    static toPlain(text: string): MessageType {
        return {
            "type": "Plain",
            "text": text
        }
    }
}

export interface Source extends MessageType {
    "type": "Source",
    "id": 123456,
    "time": 123456
}

export interface Quote {
    "type": "Quote",
    "id": 123456,
    "groupId": 123456789,
    "senderId": 987654321,
    "targetId": 9876543210,
    "origin": [
        { "type": "Plain", text: "text" }
    ]
}

export interface At {
    "type": "At",
    "target": 123456,
    "display": "@Mirai"
}

export interface AtAll {
    "type": "AtAll"
}

export interface Face {
    "type": "Face",
    "faceId": 123,
    "name": "bu"
}

export interface Plain {
    "type": "Plain",
    "text": "Mirai牛逼"
}

export interface Image {
    "type": "Image",
    "imageId": "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai",  //群图片格式
    //"imageId": "/f8f1ab55-bf8e-4236-b55e-955848d7069f"      //好友图片格式
    "url": "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "path": null,
    "base64": null
}

export interface FlashImage {
    "type": "FlashImage",
    "imageId": "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai",  //群图片格式
    //"imageId": "/f8f1ab55-bf8e-4236-b55e-955848d7069f"      //好友图片格式
    "url": "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "path": null,
    "base64": null
}

export interface Voice {
    "type": "Voice",
    "voiceId": "23C477720A37FEB6A9EE4BCCF654014F.amr",
    "url": "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "path": null,
    "base64": null
}

export interface Xml {
    "type": "Xml",
    "xml": "XML"
}

export interface Json {
    "type": "Json",
    "json": "{}"
}

export interface App {
    "type": "App",
    "content": "<>"
}

export interface Poke {
    "type": "Poke",
    "name": "SixSixSix"
}

export interface Dice {
    "type": "Dice",
    "value": 1
}

export interface MusicShare {
    "type": "MusicShare",
    "kind": "String",
    "title": "String",
    "summary": "String",
    "jumpUrl": "String",
    "pictureUrl": "String",
    "musicUrl": "String",
    "brief": "String"
}

export interface ForwardMessage {
    "type": "Forward",
    "nodeList": [
        {
            "senderId": 123,
            "time": 0,
            "senderName": "sender name",
            "messageChain": [],
            "sourceId": 123
        }
    ]
}


export interface File {
    "type": "File",
    "id": "",
    //@ts-ignore
    "name": "",
    "size": 0
}

export interface MiraiCode {
    "type": "MiraiCode",
    "code": "hello[mirai:at:1234567]"
}